import React from 'react';
import Editor from 'react-umeditor';
import Config from '../../utils/setting';
const {
  HOST
} = Config;
class SampleUpload extends React.Component {
  getQiniuUploader() {
    return {
      url: window.location.protocol + '//upload.qiniu.com',  //http || https
      type: 'qiniu',
      name: "file",
      qiniu: {
        app: {
          Bucket: Config.QINIU_BUCKET_NAME,
          AK: Config.QINIU_AK,
          SK: Config.QINIU_SK
        },
        domain: Config.QINIU_DOMAIN,
        genKey: function (options) {
          return options.file.type + "-" + options.file.size + "-" + options.file.lastModifiedDate.valueOf() + "-" + new Date().valueOf() + "-" + options.file.name;
        }
      }
    }
  }

  render() {
    // var uploader = this.getQiniuUploader();
    // var plugins = {
    //   image: {
    //     uploader: uploader
    //   }
    // }
    const plugins = {
      image: {
        uploader: {
          name: "files",
          url: `${HOST}/fs/upload/img`,
        },
      }
    };
    return (<Editor ref="editor" plugins={plugins} {...this.props} />)
  }
}

export default SampleUpload;
